/* Copyright 2011 Elektrobit Wireless Communications Oy (EB)


  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License version 2 as 
  published by the Free Software Foundation.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License along
  with this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


 *All rights reserved 
 *Version:Elektrobit_Qt_1.0.0_20110305 */


#include "routeservice.h"
#include <QDebug>
#include "dataobject.h"
#include <QWidget>
#include <QLabel>

#include <qdeclarativeengine.h>
#include <qdeclarativecontext.h>
#include <qdeclarative.h>
#include <qdeclarativeitem.h>
#include <qdeclarativeview.h>

RouteService* RouteService::service = NULL;

RouteService::RouteService(QObject *parent) :
    QObject(parent)
{
}

RouteService * RouteService::getInstance(void) {
    if(service == NULL) {
        service = new RouteService;
    }
    return service;
}


void RouteService::redirect(int nSerial) {

    if(nSerial == 1) {
        qDebug() <<"vvvvvvvvvvv" <<nSerial;
        QList<QObject*> dataList;
        for(int ii=0; ii< 2; ii++) {
            dataList.append(new DataObject("Item 21", "/home/ubuntu/work/work/multimediaGallery/cn/imageroot/film/101zhibandiangou-movie.png"));
            dataList.append(new DataObject("Item 22", "../cn/imageroot/film/huangshidehaizi-movie.png"));
            dataList.append(new DataObject("Item 23", "../cn/imageroot/film/shenhua-movie.png"));
            dataList.append(new DataObject(QString::fromUtf8("Item 225你好Item "), "../cn/imageroot/film/xiaogongzhu-movie.png"));
            dataList.append(new DataObject("Item 226", "../cn/imageroot/film/nuanchun-movie.png"));
        }

        //listviewChildernOne->hide();
        //QDeclarativeView *view = new QDeclarativeView(father);
        //listviewChildernTwo = view;
        QDeclarativeView *view = (QDeclarativeView *)listviewChildernOne;
        QDeclarativeContext *ctxt = view->rootContext();
        ctxt->setContextProperty("myModel", QVariant::fromValue(dataList));

        view->setSource(QString("view.qml"));
    //    QObject::connect(view->engine(), SIGNAL(quit()), &app, SLOT(quit()));
        view->show();

        father->show();
    }
}
